package chapter15;

public class Palindrome {

    /**
     * 回文
     */
    public static int palindrome(String[] X, String[] Y, int i, int j, int[][] c) {
        // character
        // retcarahc
        if (i == 0 || j == 0) {
            return 0;
        }
        if (c[i][j] != 0) {
            return c[i][j];
        }
        if (X[i - 1].equals(Y[j - 1])) {
            return c[i][j] = palindrome(X, Y, i - 1, j - 1, c) + 1;
        }
        return c[i][j] = Math.max(palindrome(X, Y, i - 1, j, c), palindrome(X, Y, i, j - 1, c));
    }

}
